﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ATW.MT.BUS;
using ATW.MT.CommonClass;
using BUS;

namespace ATW.MT.SellManage
{
    public partial class _addSeller : System.Web.UI.Page
    {
        bus_T_appuser au = new bus_T_appuser();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] == null)
            {
                Response.Redirect("../Main/Login.aspx");
            }
        }
        protected void lbnSave_Click(object sender, EventArgs e)
        {
            string name = txtName.Text.Trim();
            string account = txtAccount.Text.Trim();
            string pwd = txtPwd.Text.Trim();
            string pwd2 = txtPwd2.Text.Trim();
            string Mail = txtMail.Text.Trim();
            try
            {
                if (name == "")
                {
                    Tips("请输入销售真实姓名！");
                    return;
                }
                if (account == "")
                {
                    Tips("请输入账号！");
                    return;
                }
                if (pwd == "")
                {
                    Tips("请输入密码！");
                    return;
                }
                if (pwd2 != pwd)
                {
                    Tips("两次密码不一致，请重新输入！");
                    return;
                }
                if (!common.filterChar(name))
                {
                    Tips("姓名中含有非法字符！");
                    return;
                }
                if (!common.filterChar(account))
                {
                    Tips("账号中存在非法字符！");
                    return;
                }
                if (!common.filterChar(pwd))
                {
                    Tips("密码中含有非法字符！");
                    return;
                }
                if (au.isSellerExist(account))
                {
                    Tips("该账号已经存在！");
                    return;
                }
                string code = new CommonHelp().GetInviteCode("B");
                int result = au.SellerAdd(name, account, pwd, code,Mail);
                if (result > 0)
                {
                    Tips("新增成功！");
                    CloseWindowReferesh();
                }
                else
                {
                    Tips("新增失败！");
                }
            }
            catch (Exception ex)
            {
 
            }
        }
        private void Tips(string s)
        {//提示
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }
        private void CloseWindowReferesh()
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                if(window.opener)
                {
                    window.opener.location.href=window.opener.location.href;
                    window.close();
                }
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "Close", strScript.ToString());
        }
    }
}